<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>华悦假日酒店 | 忘记密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="icon" href="../../images/favicon.jpg" sizes="32x32">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/login.css" media="all">
</head>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>华悦假日酒店</h2>
            <p>华悦假日酒店后台管理系统</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">

            <script type="text/html" template>
                {{# if(layui.router().search.type === 'resetpass'){ }}
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-password"></label>
                    <input type="password" name="password" id="LAY-user-login-password" lay-verify="pass"
                           placeholder="新密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                           for="LAY-user-login-repass"></label>
                    <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required"
                           placeholder="确认密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-forget-resetpass">重置新密码
                    </button>
                </div>
                {{# } else { }}
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone"
                           for="LAY-user-login-cellphone"></label>
                    <input type="text" name="cellphone" id="LAY-user-login-cellphone" lay-verify="phone"
                           placeholder="请输入您的手机号" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs12">
                            <div id="user-forget-slider"></div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                                   for="LAY-user-login-smscode"></label>
                            <input type="text" name="vercode" id="LAY-user-login-smscode" lay-verify="required"
                                   placeholder="短信验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid"
                                        id="LAY-user-getsmscode">获取验证码
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-forget-submit">找回密码
                    </button>
                </div>
                {{# } }}
            </script>
        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">
        <p>© 2020
            <a href="/pages/desk/index.jsp" target="_blank">huayue.com</a>
            <a href="login.html">登录</a>
        </p>
    </div>

</div>

<script src="../../js/jquery-1.8.3.min.js"></script>
<script src="../../layuiadmin/layui/layui.js"></script>
<script>
    var slider = null;

    layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user', 'sliderVerify'], function () {
        var $ = layui.$
            , setter = layui.setter
            , admin = layui.admin
            , form = layui.form
            , router = layui.router();
        //修饰验证条
        var sliderVerify = layui.sliderVerify,
            form = layui.form;
        slider = sliderVerify.render({
            elem: '#user-forget-slider'
        });
        form.render();

        //找回密码下一步
        form.on('submit(LAY-user-forget-submit)', function (obj) {
            var field = obj.field;
            var sendlayer02 = layer.load(1, {
                shade: [0.2, '#fff']
            });
            //请求接口
            admin.req({
                url: '/user/findAuthCodeByUserInfo'
                , data: {
                    "phone": $("#LAY-user-login-cellphone").val(),
                    "authCode": $("#LAY-user-login-smscode").val()
                }
                , dataType: "json"
                , done: function (res) {
                    layer.close(sendlayer02);
                    if (res.status) {
                        location.hash = '/type=resetpass';
                        location.reload();
                    } else {
                        layer.msg(res.msg, {icon: 2})
                    }
                }
            });

            return false;
        });

        //重置密码
        form.on('submit(LAY-user-forget-resetpass)', function (obj) {
            var field = obj.field;

            //确认密码
            if (field.password !== field.repass) {
                return layer.msg('两次密码输入不一致');
            }
            var sendlayer03 = layer.load(1, {
                shade: [0.2, '#fff']
            });
            //请求接口
            admin.req({
                url: '/user/updatePassword' //实际使用请改成服务端真实接口
                , data: field
                , done: function (res) {
                    layer.close(sendlayer03);
                    layer.msg(res.msg, {
                        offset: '15px'
                        , icon: res.icon
                        , time: 1500
                    }, function () {
                        location.href = 'login.html'; //跳转到登入页
                    });
                }
            });

            return false;
        });
    });
</script>

</html>